/*

 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The software in this package is published under the terms of the GPL v2.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE-GPL.txt file.
 */

package org.cemantika.management;

import org.cemantika.contextconsumer.ContextConsumerAdapter;
import org.cemantika.exception.KnowledgeSessionAlreadyCreatedException;
import org.cemantika.exception.KnowledgeSessionNotCreatedException;
import org.cemantika.exception.LoadKnowledgeSessionException;
import org.cemantika.management.drools.DroolsContextualManipulation;

/**
 * ContextualManipulation represents the manipulation of contextual information.
 * 
 * @author andersonfellipe
 */
public interface ContextualManipulation {

    /**
     * Creates a new knowledge session and returns its session id useful when the persistence is
     * active.
     * 
     * @return the sessionId the id of the session.
     */
    public int newKnowledgeSession() throws KnowledgeSessionAlreadyCreatedException;

    /**
     * Creates a new knowledge session retrieved from the database when the persistence is active.
     * 
     * @param sessionId the id of the session.
     */
    public void loadKnowledgeSession(int sessionId) throws LoadKnowledgeSessionException;

    /**
     * Add the focus to the foci being manipulated by CEManTIKA.
     * 
     * @param focus the {@link ContextConsumerAdapter} to add.
     */
    public void addFocus(ContextConsumerAdapter focus) throws KnowledgeSessionNotCreatedException;

    /**
     * Remove the focus from the foci being manipulated by CEManTIKA.
     * 
     * @param focus the {@link ContextConsumerAdapter} to remove.
     */
    public void removeFocus(ContextConsumerAdapter focus) throws KnowledgeSessionNotCreatedException;

    /**
     * Update the focus being manipulated by CEManTIKA.
     * 
     * @param focus the {@link ContextConsumerAdapter} to update.
     */
    public void updateFocus(ContextConsumerAdapter focus) throws KnowledgeSessionNotCreatedException;

    /**
     * Represents the test if the focus is being manipulated by CEManTIKA.
     * 
     * @param focus the {@link ContextConsumerAdapter} to test.
     * @return true if the focus is registered.
     */
    public boolean isFocusRegistered(ContextConsumerAdapter focus);
    
    /**
     * Represents the test if the {@link DroolsContextualManipulation} has a knowledge session.
     * 
     * @return true if has a knowledge session.
     */
    public boolean hasKnowledgeSession();

    /**
     * Represents the halt of the inference engine.
     */
    public void terminate() throws KnowledgeSessionNotCreatedException;

    /**
     * Represents the clearing of all focus added to be managed by CEManTIKA.
     */
    public void clearContextualMemory() throws KnowledgeSessionNotCreatedException;

}
